<#
.SYNOPSIS
验证学生管理系统的基本功能

.DESCRIPTION
此脚本用于验证学生管理系统的Docker容器是否正常运行。

.NOTES
运行此脚本需要安装Docker和Docker Compose
#>

# 检查Docker是否已安装和运行
Write-Host "正在检查Docker状态..."
if (-not (Get-Command "docker" -ErrorAction SilentlyContinue)) {
    Write-Error "未找到Docker。请先安装Docker Desktop。"
    Exit
}

try {
    docker info > $null
} catch {
    Write-Error "Docker未运行。请先启动Docker Desktop。"
    Exit
}

# 检查系统容器状态
Write-Host "\n正在检查系统容器状态..."
docker ps --filter "name=student-management-"

# 检查MySQL容器
Write-Host "\n正在检查MySQL数据库连接..."
try {
    docker exec student-management-db mysql -u admin -p123456 -e "SELECT 1;" -s -N > $null
    Write-Host "MySQL数据库连接成功！"
} catch {
    Write-Warning "MySQL数据库连接失败，可能是服务尚未完全启动。"
}

# 检查后端API
Write-Host "\n正在检查后端API服务..."
try {
    $apiUrl = "http://localhost:5000/swagger/index.html"
    $response = Invoke-WebRequest -Uri $apiUrl -UseBasicParsing -TimeoutSec 10
    Write-Host "后端API服务正常运行！访问地址：$apiUrl"
} catch {
    Write-Warning "后端API服务不可达，可能是服务尚未完全启动。"
}

# 检查前端应用
Write-Host "\n正在检查前端应用服务..."
try {
    $frontendUrl = "http://localhost:80"
    $response = Invoke-WebRequest -Uri $frontendUrl -UseBasicParsing -TimeoutSec 10
    Write-Host "前端应用服务正常运行！访问地址：$frontendUrl"
} catch {
    Write-Warning "前端应用服务不可达，可能是服务尚未完全启动。"
}

# 显示登录信息
Write-Host "\n系统默认账号信息："
Write-Host "- 管理员: admin / Admin@123"
Write-Host "- 教师: teacher / Teacher@123"
Write-Host "- 学生: student / Student@123"

Write-Host "\n停止系统命令：docker-compose -f docker\docker-compose.yml down"